import jQuery from 'jquery'
import 'popper.js'
import 'bootstrap'

import http from 'axios'


Promise.all([http({
  url: 'https://gank.io/api/v2/categories/Girl'
}), http({
  url: 'https://gank.io/api/v2/categories/Article'
})]).then(res => {
  let menuData = []
  res.forEach((item) => {
    const { data } = item.data
    menuData = [...menuData, ...data]
  })

  menuData.forEach((item) => {
    const { title } = item
    // console.log(item)
    jQuery(`<li class="nav-item">
          <a class="nav-link" href="javascript:void(0)">${title}</a>
        </li>`).appendTo('.my-menu')
  })
}).catch(e => {
  console.log(e)
})

// list html
http({
  url: 'https://gank.io/api/v2/data/category/All/type/All/page/1/count/20'
}).then(res => {
  const {data} = res.data
  console.info(res.data)
  console.log(data)
  data.forEach((item) => {
    console.log(item)
    const { images, desc, title, _id: id } = item
    jQuery(`<div class="col-xl-3 col-lg-4 col-md-6 col-sm-12">
      <div class="card">
        <img src="${images[0]}" class="card-img-top" alt="...">
        <div class="card-body">
          <h5 class="card-title">${title}</h5>
          <p class="card-text">${desc}</p>
          <a href="./article.html?id=${id}" class="btn btn-primary">查看详情</a>
        </div>
      </div>
    </div>`).appendTo('.my-list')
  })
}).catch(e => {
  console.log(e)
}).finally(() => {
  console.log('ok!')
})



// console.log(http)
// https://gank.io/api/v2/categories/Girl
// 妹纸
// https://gank.io/api/v2/categories/Article
// Android 苹果 Flutter 前端 App

// 回调地狱
/*let menuData = []
http({
  url: 'https://gank.io/api/v2/categories/Girl'
}).then(res => {
  // console.log(res.data.data)
  // menuData = [...res.data.data]
  menuData = menuData.concat(res.data.data)
  http({
    url: 'https://gank.io/api/v2/categories/Article'
  }).then(res => {
    // menuData = [...menuData, ...res.data.data]
    menuData = menuData.concat(res.data.data)
    console.log(menuData)
    // console.log(res.data.data)
  })
})*/




http({
  method: 'GET',
  url: 'https://gank.io/api/v2/banners',
}).then((res) => {
  // success
  const { data } = res.data
  // console.log(data)

}).catch(e => {
  // error
  console.log(e)
  
}).finally(() => {
  console.log('已完成')
})



